package com.android.myapplication.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import com.android.myapplication.R;
import com.android.myapplication.main.BaseActvity;

public class StyleActivity extends BaseActvity {
    static boolean mIsBigText;
    static boolean mIsNoTitleBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTheme(mIsNoTitleBar ? android.R.style.Theme_Material : android.R.style.Theme_Material_Light);
        setContentView(R.layout.activity_style);
        init();
        ((TextView)findViewById(R.id.txt_view)).setTextAppearance(mIsBigText ?  R.style.big_text : R.style.small_text);
        ((Switch)findViewById(R.id.switch_text_style)).setChecked(mIsBigText);
        ((Switch)findViewById(R.id.switch_activity_style)).setChecked(mIsNoTitleBar);

        ((Switch)findViewById(R.id.switch_text_style)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mIsBigText = isChecked;
                ((TextView)findViewById(R.id.txt_view)).setTextAppearance(isChecked ?  R.style.big_text : R.style.small_text);
            }
        });
        ((Switch)findViewById(R.id.switch_activity_style)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mIsNoTitleBar = isChecked;
                StyleActivity.this.setTheme(mIsNoTitleBar ? android.R.style.Theme_Material : android.R.style.Theme_Material_Light);
                finish();
                Intent intent = new Intent(getApplicationContext(), StyleActivity.class);
                intent.putExtra(TextActivity.ARG_ITEM_ID, "5");
                startActivity(intent);
            }
        });
    }
}